import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
const routerList = [
  { path: '/base-button', name: 'button',  meta: {title:'按钮'} },
  { path: '/base-cascader', name: 'cascader',  meta: {title:'自动补全输入框'} },
  { path: '/base-checkbox', name: 'checkbox',  meta: {title:'多选框'} },
  { path: '/base-date-picker', name: 'date-picker',  meta: {title:'日期选择器'} },
  { path: '/base-input', name: 'input',  meta: {title:'输入框'} },
  { path: '/base-input-number', name: 'input-number',  meta: {title:'数字输入框'} },
  { path: '/base-radio', name: 'radio', meta: {title:'单选框'} },
  { path: '/base-rate', name: 'rate', meta: {title:'评分'} },
  { path: '/base-select', name: 'select',meta: {title:'下拉框'} },
  { path: '/base-slider', name: 'slider',meta: {title:'滑块'} },
  { path: '/base-switch', name: 'switch', meta: {title:'开关'} },
  { path: '/base-form', name: 'form', meta: {title:'表单'} },
  { path: '/base-table', name: 'table', meta: {title:'表格'} },
  { path: '/base-page', name: 'page',meta: {title:'分页'} },
]
const addRouter = () => { 
  return routerList.map(item => { 
    const { path,name,meta}=item
    return {
      path,
      name,
      component:() => import(`@/views/base/${name}.vue`),
      meta
    }
  })
}
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'layout',
    redirect:"/base-button",
    component: () => import('../views/layout.vue'),
    children: addRouter()
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((guard) => { 
  if (guard && guard.meta && guard.meta.title) { 
    document.title=guard.meta.title as string
  }
})
export default router
